const router = require('koa-router')()
const ORDER = require('../models/order')
const auth = require("../utils");

//查询
router.get('/', auth,async function (ctx, next) {
    ctx.body = await ORDER.find({user:ctx.state.user._id}).populate(['user','goods'])
})
// 新增
router.post('/', auth, async function (ctx, next) {
    let data = ctx.request.body
    data.user = ctx.state.user._id
    ctx.body = await ORDER.create(data)
})

// 修改
router.put('/:id', auth, async function (ctx, next) {
    ctx.body = await ORDER.findByIdAndUpdate(ctx.params.id,ctx.request.body)
})

// 删除
router.delete('/:id', auth, async function (ctx, next) {
    ctx.body = await ORDER.findByIdAndDelete(ctx.params.id)
})


module.exports = router
